package com.fox.stock.pojo.domain;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.fox.stock.pojo.entity.SysPermission;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@ApiModel("权限类")
@Data
public class PermissionDomain {
    /**
     * 权限id
     */
    @ApiModelProperty("权限id")
    @JsonSerialize(using = ToStringSerializer.class)// 转化为json数据时 以字符串形式传
    private long id;

    /**
     * 权限标题
     */
    @ApiModelProperty("权限标题")
    private String title;

    /**
     * 权限图标
     */
    @ApiModelProperty("权限图标")
    private String icon;

    /**
     * 请求地址
     */
    @ApiModelProperty("请求地址")
    private String path;

    /**
     * 权限名称对应前端vue组件名称
     */
    @ApiModelProperty("权限名称对应前端vue组件名称")
    private String name;

    /**
     * 次级权限
     */
    @ApiModelProperty("次级权限")
    private List<PermissionDomain> children;


    public static PermissionDomain  changeBySysPermission(SysPermission sysPermission){
        PermissionDomain permissionDomain = new PermissionDomain();
        permissionDomain.setId(sysPermission.getId());
        permissionDomain.setIcon(sysPermission.getIcon());
        permissionDomain.setPath(sysPermission.getUrl());
        permissionDomain.setName(sysPermission.getName());
        permissionDomain.setTitle(sysPermission.getTitle());
        permissionDomain.setChildren(new ArrayList<>());
        return permissionDomain;
    }
}
